using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VITPRS
    {
        public DataRow Convert2ITPRS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryITPRS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ITPPID"] = " ".PadRight(0 ); 
         dwReturn["ITPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ITPLFDNR"] = " ".PadRight(0 ); 
         dwReturn["ITPDATUM"] = " ".PadRight(0 ); 
         dwReturn["ITPZEIT"] = " ".PadRight(0 ); 
         dwReturn["ITPMPID"] = " ".PadRight(0 ); 
         dwReturn["ITPTYP"] = " ".PadRight(1 ); 
         dwReturn["ITPCTYP"] = " ".PadRight(1 ); 
         dwReturn["ITPPNAME"] = " ".PadRight(12 ); 
         dwReturn["ITPTERM"] = " ".PadRight(8 ); 
         dwReturn["ITPLGNAME"] = " ".PadRight(8 ); 
         dwReturn["ITPUNAME"] = " ".PadRight(8 ); 
         dwReturn["ITPINST"] = " ".PadRight(0 ); 
         dwReturn["ITPDAUFTNR"] = " ".PadRight(4 ); 
         dwReturn["ITPEXITCODE"] = " ".PadRight(0 ); 
         dwReturn["ITPCLIENTIP"] = " ".PadRight(18 ); 
         dwReturn["ITPCLIENTVER"] = " ".PadRight(4 ); 
         dwReturn["ITPPROTOVER"] = " ".PadRight(4 ); 
         dwReturn["ITPLADATE"] = " ".PadRight(0 ); 
         dwReturn["ITPLATIME"] = " ".PadRight(0 ); 
         dwReturn["ITPLAPROG"] = " ".PadRight(8 ); 
         dwReturn["ITPAPROG"] = " ".PadRight(8 ); 
         dwReturn["ITPLIZTYP"] = " ".PadRight(4 ); 
         dwReturn["ITPSERVER"] = " ".PadRight(32 ); 
         dwReturn["ITPSID"] = " ".PadRight(0 ); 
         dwReturn["ITPFILLER"] = " ".PadRight(90 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapITPRS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveITPRS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryITPRS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapITPRS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertITPRS(dwLocal, ITXDBVERSION);
            }
            UpdateITPRS(dwLocal);
        }
        public void InsertITPRS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ITPRS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryITPRS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ITPRS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ITPRS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ITPRS";
            Return = Result;
            return Return;
        }
        public void DeleteITPRS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ITPRS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateITPRS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ITPRS SET "
                    +"ITPPID= :ITPPID,"
                    +"ITPMANDANT= :ITPMANDANT,"
                    +"ITPLFDNR= :ITPLFDNR,"
                    +"ITPDATUM= :ITPDATUM,"
                    +"ITPZEIT= :ITPZEIT,"
                    +"ITPMPID= :ITPMPID,"
                    +"ITPTYP= :ITPTYP,"
                    +"ITPCTYP= :ITPCTYP,"
                    +"ITPPNAME= :ITPPNAME,"
                    +"ITPTERM= :ITPTERM,"
                    +"ITPLGNAME= :ITPLGNAME,"
                    +"ITPUNAME= :ITPUNAME,"
                    +"ITPINST= :ITPINST,"
                    +"ITPDAUFTNR= :ITPDAUFTNR,"
                    +"ITPEXITCODE= :ITPEXITCODE,"
                    +"ITPCLIENTIP= :ITPCLIENTIP,"
                    +"ITPCLIENTVER= :ITPCLIENTVER,"
                    +"ITPPROTOVER= :ITPPROTOVER,"
                    +"ITPLADATE= :ITPLADATE,"
                    +"ITPLATIME= :ITPLATIME,"
                    +"ITPLAPROG= :ITPLAPROG,"
                    +"ITPAPROG= :ITPAPROG,"
                    +"ITPLIZTYP= :ITPLIZTYP,"
                    +"ITPSERVER= :ITPSERVER,"
                    +"ITPSID= :ITPSID,"
                    +"ITPFILLER= :ITPFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ITPPID", OracleType.NVarChar).Value = dwData["ITPPID"].ToString(); 
          or1.Parameters.Add("ITPMANDANT", OracleType.NVarChar).Value = dwData["ITPMANDANT"].ToString(); 
          or1.Parameters.Add("ITPLFDNR", OracleType.NVarChar).Value = dwData["ITPLFDNR"].ToString(); 
          or1.Parameters.Add("ITPDATUM", OracleType.NVarChar).Value = dwData["ITPDATUM"].ToString(); 
          or1.Parameters.Add("ITPZEIT", OracleType.NVarChar).Value = dwData["ITPZEIT"].ToString(); 
          or1.Parameters.Add("ITPMPID", OracleType.NVarChar).Value = dwData["ITPMPID"].ToString(); 
          or1.Parameters.Add("ITPTYP", OracleType.NVarChar).Value = dwData["ITPTYP"].ToString(); 
          or1.Parameters.Add("ITPCTYP", OracleType.NVarChar).Value = dwData["ITPCTYP"].ToString(); 
          or1.Parameters.Add("ITPPNAME", OracleType.NVarChar).Value = dwData["ITPPNAME"].ToString(); 
          or1.Parameters.Add("ITPTERM", OracleType.NVarChar).Value = dwData["ITPTERM"].ToString(); 
          or1.Parameters.Add("ITPLGNAME", OracleType.NVarChar).Value = dwData["ITPLGNAME"].ToString(); 
          or1.Parameters.Add("ITPUNAME", OracleType.NVarChar).Value = dwData["ITPUNAME"].ToString(); 
          or1.Parameters.Add("ITPINST", OracleType.NVarChar).Value = dwData["ITPINST"].ToString(); 
          or1.Parameters.Add("ITPDAUFTNR", OracleType.NVarChar).Value = dwData["ITPDAUFTNR"].ToString(); 
          or1.Parameters.Add("ITPEXITCODE", OracleType.NVarChar).Value = dwData["ITPEXITCODE"].ToString(); 
          or1.Parameters.Add("ITPCLIENTIP", OracleType.NVarChar).Value = dwData["ITPCLIENTIP"].ToString(); 
          or1.Parameters.Add("ITPCLIENTVER", OracleType.NVarChar).Value = dwData["ITPCLIENTVER"].ToString(); 
          or1.Parameters.Add("ITPPROTOVER", OracleType.NVarChar).Value = dwData["ITPPROTOVER"].ToString(); 
          or1.Parameters.Add("ITPLADATE", OracleType.NVarChar).Value = dwData["ITPLADATE"].ToString(); 
          or1.Parameters.Add("ITPLATIME", OracleType.NVarChar).Value = dwData["ITPLATIME"].ToString(); 
          or1.Parameters.Add("ITPLAPROG", OracleType.NVarChar).Value = dwData["ITPLAPROG"].ToString(); 
          or1.Parameters.Add("ITPAPROG", OracleType.NVarChar).Value = dwData["ITPAPROG"].ToString(); 
          or1.Parameters.Add("ITPLIZTYP", OracleType.NVarChar).Value = dwData["ITPLIZTYP"].ToString(); 
          or1.Parameters.Add("ITPSERVER", OracleType.NVarChar).Value = dwData["ITPSERVER"].ToString(); 
          or1.Parameters.Add("ITPSID", OracleType.NVarChar).Value = dwData["ITPSID"].ToString(); 
          or1.Parameters.Add("ITPFILLER", OracleType.NVarChar).Value = dwData["ITPFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
